#include <bits/stdc++.h>
#define rep(i, l, r) for (int i = l; i <= r; ++i)
using namespace std;
unordered_set<int> G[205];
int main() {
    int n, m, u, v;
    cin >> n >> m;
    rep(i, 1, m) {
        cin >> u >> v;
        G[u].insert(v);
        G[v].insert(u);
    }
    cin >> m;
    rep(_, 1, m) {
        int k;
        cin >> k;
        vector<int> p(k);
        for (int &x : p) cin >> x;

        unordered_set<int> uq;
        for (int i = 1; i < k; ++i) uq.insert(p[i]);
        if (k != n + 1 || uq.size() != n || p.back() != p.front()) {
            puts("NO");
            continue;
        }

        int cnt = 0;
        for (int i = 0; i < k - 1; ++i) {
            if (!G[p[i]].count(p[(i + 1) % k])) {
                ++cnt;
            }
        }
        puts(cnt == 0 ? "YES" : "NO");
    }
    return 0;
}